package com.yb.nowcoder;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main002 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String s = in.nextLine();
            Map<String, Node> map = new HashMap<>();
            Node head = new Node(String.valueOf(s.charAt(0)));
            map.put(String.valueOf(s.charAt(0)), head);
            Node currentNode = head;
            for (int i = 1; i < s.length(); i++) {
                String si = String.valueOf(s.charAt(i));
                if (!map.containsKey(si)) {
                    Node node = new Node(si);
                    map.put(si, node);
                    currentNode.next = node;
                    currentNode = currentNode.next;
                } else {
                    currentNode.next = map.get(si);
                    break;
                }
            }
            System.out.println(loop(head));
        }
    }

    public static String loop(Node head) {
        Node slow = head, fast = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) {
                fast = head;
                while (fast != slow) {
                    slow = slow.next;
                    fast = fast.next;
                }
                return fast.value;
            }
        }
        return "0";
    }

    static class Node {
        String value;
        Node next;

        public Node(String value) {
            this.value = value;
        }
    }
}
